﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;

namespace IHISCETeim.Web.MachineSys.MacModel
{
    public partial class ODailyReport : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "ODailyReport";
            }
        }
        #region 属性 (查询条件)

       

        protected string WorkDateForm
        {
            get
            {
                return GetRequestValue<string>("WorkDateForm", GetQuarterDate(DateTime.Now.Year, GetNowQuarter(DateTime.Now), true));

            }
        }

        protected string WorkDateTo
        {
            get
            {
                return GetRequestValue<string>("WorkDateTo", DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"));
            }
        }

        protected string ReportType
        {
            get
            {
                return GetRequestValue<string>("ReportType","1");
            }
        }

        #endregion
        private string GetQuarterDate(int year, int quarter, bool isstart)
        {
            DateTime dt = new DateTime(year, quarter * 3, 1);
            DateTime startQuarter = dt.AddMonths(0 - (dt.Month - 1) % 3).AddDays(1 - dt.Day);  //本季度初
            DateTime endQuarter = startQuarter.AddMonths(3).AddDays(-1);  //本季度末
            return isstart ? startQuarter.ToString("yyyy-MM-dd") : endQuarter.ToString("yyyy-MM-dd");
        }

        /// <summary>
        /// 获取时间所在季度值
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        private int GetNowQuarter(DateTime dt)
        {
            int nowQuarter = 1;
            int month = dt.Month;
            if (month >= 1 && month <= 3)
                nowQuarter = 1;
            if (month >= 4 && month <= 6)
                nowQuarter = 2;
            if (month >= 7 && month <= 9)
                nowQuarter = 3;
            if (month >= 10 && month <= 12)
                nowQuarter = 4;
            return nowQuarter;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.AddLog(Permission.查看);
            //switch (ReportType)
            //{
            //    case "1":
            //        DataBind1();
            //        break;
            //    case "2":
            //        DataBind2();
            //        break;
            //    case "3":
            //        DataBind3();
            //        break;
            //    case "4":
            //        DataBind4();
            //        break;
            //}
            //DataBind();
        }

        //protected void DataBind1()
        //{
        //    DataTable dt = ODailyController.GetMachineTaskTimeChart(WorkDateForm, WorkDateTo);
        //    rpMachineTaskTimeChart.DataSource = dt;
        //    rpMachineTaskTimeChart.DataBind();
        //    MachineTaskTimeChart.DataSource = dt;
        //    MachineTaskTimeChart.Series["Series1"].XValueMember = "SerialNumber";
        //    MachineTaskTimeChart.Series["Series1"].YValueMembers = "TaskTime";
        //    MachineTaskTimeChart.DataBind();

        //    double tasktimes=0;
        //    foreach (DataRow dr in dt.Rows)
        //    {
        //        tasktimes = tasktimes + Convert.ToDouble(dr["TaskTime"]);
        //    }

        //    MachineTaskTimeChart.Titles["TaskTimeTitle"].Text = string.Format("从{0}到{1}总直接工时为{2}分钟", WorkDateForm, WorkDateTo, tasktimes);
        //   // this.rpMenu.DataSource = ODailyController.GetPagination(UserName, SerialNumber, pageNum, numPerPage, orderField, ref TotalCount);
        //   // this.rpMenu.DataBind();
        //}

        //protected void DataBind2()
        //{
        //    //chart2
        //    double tasktime1 = 0;
        //    double tasktime2 = 0;
        //    double alltasktime = 0;
        //    tasktime1 = ODailyController.GetZJJJTaskTime(WorkDateForm, WorkDateTo,"直接");
        //    tasktime2 = ODailyController.GetZJJJTaskTime(WorkDateForm, WorkDateTo, "间接");
        //    alltasktime = tasktime1 + tasktime2;

        //    this.chart2.Titles["detailTitle"].Text = string.Format(this.chart2.Titles["detailTitle"].Text, WorkDateForm, WorkDateTo, alltasktime);
        //    chart2.Series["Series1"].Points[0].YValues = new double[] { tasktime1 / alltasktime };
        //    chart2.Series["Series1"].Points[1].YValues = new double[] { tasktime2 / alltasktime };

        //    chart2.Series["Series1"].Points[0].LegendText =string.Format("直接{0}分钟",tasktime1);
        //    chart2.Series["Series1"].Points[1].LegendText = string.Format("间接{0}分钟", tasktime2);
        
        //}
        //protected void DataBind3()
        //{
        //    DataTable dt = ODailyController.GetMachineTaskTime3(WorkDateForm, WorkDateTo);
        //    rpMachineTaskTimeChart3.DataSource = dt;
        //    rpMachineTaskTimeChart3.DataBind();
        //    MachineTaskTimeChart3.DataSource = dt;
        //    MachineTaskTimeChart3.Series["Series1"].XValueMember = "SerialNumber";
        //    MachineTaskTimeChart3.Series["Series1"].YValueMembers = "alltasktime";
        //    MachineTaskTimeChart3.DataBind();

        //    double tasktimes = 0;
        //    foreach (DataRow dr in dt.Rows)
        //    {
        //        tasktimes = tasktimes + Convert.ToDouble(dr["alltasktime"]);
        //    }

        //    MachineTaskTimeChart3.Titles["TaskTimeTitle"].Text = string.Format(MachineTaskTimeChart3.Titles["TaskTimeTitle"].Text, WorkDateForm, WorkDateTo, tasktimes);
        //}
        //protected void DataBind4()
        //{
        //    DataTable dt = ODailyController.GetMachineTaskTime4(WorkDateForm, WorkDateTo);
        //    rpMachineTaskTimeChart4.DataSource = dt;
        //    rpMachineTaskTimeChart4.DataBind();
        //    MachineTaskTimeChart4.DataSource = dt;
        //    MachineTaskTimeChart4.Series["Series1"].XValueMember = "GongWei";
        //    MachineTaskTimeChart4.Series["Series1"].YValueMembers = "TaskTime";
        //    MachineTaskTimeChart4.DataBind();

        //    //double tasktimes = 0;
        //    //foreach (DataRow dr in dt.Rows)
        //    //{
        //    //    tasktimes = tasktimes + Convert.ToDouble(dr["TaskTime"]);
        //    //}

        //    //MachineTaskTimeChart.Titles["TaskTimeTitle"].Text = string.Format("从{0}到{1}总直接工时为{2}分钟", WorkDateForm, WorkDateTo, tasktimes);
        //}
    }
}